/*
 * Microsoft .NET  2.0+ version of Sphinx searchd client (Sphinx API)
 * 
 * Copyright (c) 2009, Shaun Berryman
 * All rights reserved
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License. You should have
 * received a copy of the GPL license along with this program; if you
 * did not, you can find it at http://www.gnu.org/
 */

using System;
using System.Collections.Generic;
using System.Text;

namespace SphinxSearchApi.Model
{
    public class SearchResult
    {
        /// <summary>
        /// Full-text field names
        /// </summary>
        public string[] Fields { get; set; }

        /// <summary>
        /// Attribute names
        /// </summary>
        public string[] AttributeNames { get; set; }

        /// <summary>
        /// Attribute types
        /// </summary>
        public AttributeEnum[] AttributeTypes { get; set; }

        /// <summary>
        /// Retrieved matches
        /// </summary>
        public Match[] Matches { get; set; }

        /// <summary>
        /// Total matches in this result set.
        /// </summary>
        public int Total { get; set; }

        /// <summary>
        /// Total matches found in the index(es).
        /// </summary>
        public int TotalFound { get; set; }

        /// <summary>
        /// Elapsed time (as reported by searchd), in seconds.
        /// </summary>
        public float Time { get; set; }

        /// <summary>
        /// Per-word statistics.
        /// </summary>
        public WordInfo[] Words { get; set; }

        /// <summary>
        /// Warning message, if any.
        /// </summary>
        public string Warning { get; set; }

        /// <summary>
        /// Error message, if any.
        /// </summary>
        public string Error { get; set; }

        /** Query status (refer to SEARCHD_xxx constants in SphinxClient). */
        private int _Status = -1;
        public StatusEnum Status
        {
            get { return (StatusEnum)_Status; }
        }
        
        /** Trivial constructor, initializes an empty result set. */
        public SearchResult()
        {
            this.AttributeNames = new string[0];
            this.Matches = new Match[0]; ;
            this.Words = new WordInfo[0];
            this.Fields = new String[0];
            this.AttributeTypes = new AttributeEnum[0];
        }

        /// <summary>
        /// Set query status (accessible from API package only)
        /// </summary>
        /// <param name="status"></param>
        internal SearchResult SetStatus(int status)
        {
            this._Status = status;

            return this;
        }
    }
}
